# Setting batch to true, triggers one build at a time.
# if there is a push while a build in progress, it will wait,
# until the running build finishes, and produce a build with all the changes
# that happened during the last build.
trigger:
  batch: true
  branches:
    include:
    - release/*.*
  paths:
    include:
    - '*'
    exclude:
    - '**.md'
    - eng/Version.Details.xml
    - .devcontainer/*
    - .github/*
    - docs/*
    - LICENSE.TXT
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT

schedules:
  - cron: "0 8,20 * * *" # run at 8:00 and 20:00 (UTC) which is 00:00 and 12:00 (PST).
    displayName: Runtime default schedule
    branches:
      include:
      - main
    always: false # run only if there were changes since the last successful scheduled run.

pr:
  branches:
    include:
    - main
    - release/*.*
  paths:
    include:
    - '*'
    exclude:
    - '**.md'
    - eng/Version.Details.xml
    - .devcontainer/*
    - .github/*
    - docs/*
    - LICENSE.TXT
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT

variables:
  - template: /eng/pipelines/common/variables.yml

extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
      - stage: EvaluatePaths
        displayName: Evaluate Paths
        jobs:
          - template: /eng/pipelines/common/evaluate-default-paths.yml

    - stage: Build
      jobs:
      #
      # Build Mono and Installer on LLVMJIT mode
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: Release
          runtimeFlavor: mono
          platforms:
          - osx_x64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMJIT
            buildArgs: -s mono+libs+host+packs -c $(_BuildConfig)
                      /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=false
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
          runtimeFlavor: mono
          platforms:
          - linux_x64
          - linux_arm64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMJIT
            buildArgs: -s mono+libs+host+packs -c $(_BuildConfig)
                      /p:MonoEnableLLVM=true /p:MonoBundleLLVMOptimizer=false
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build Mono and Installer on LLVMAOT mode
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: Release
          runtimeFlavor: mono
          platforms:
          - linux_x64
          - linux_arm64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMAOT
            buildArgs: -s mono+libs+host+packs -c $(_BuildConfig)
                      /p:MonoEnableLLVM=true /p:MonoAOTEnableLLVM=true /p:MonoBundleLLVMOptimizer=true
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
          runtimeFlavor: mono
          platforms:
          - osx_x64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMAOT
            buildArgs: -s mono+libs+host+packs -c $(_BuildConfig)
                      /p:MonoEnableLLVM=true /p:MonoAOTEnableLLVM=true /p:MonoBundleLLVMOptimizer=true
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
          buildConfig: release
          runtimeFlavor: mono
          platforms:
          - linux_x64
          # Disabled pending outcome of https://github.com/dotnet/runtime/issues/60234 investigation
          #- linux_arm64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMAOT_RuntimeTests
            buildArgs: -s mono+clr.iltools+clr.hosts+libs+host+packs -c $(_BuildConfig) -lc ${{ variables.debugOnPrReleaseOnRolling }}
                      /p:MonoEnableLLVM=true /p:MonoAOTEnableLLVM=true /p:MonoBundleLLVMOptimizer=true
            postBuildSteps:
              - template: /eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml
                parameters:
                  creator: dotnet-bot
                  testRunNamePrefixSuffix: Mono_Release
                  llvmAotStepContainer: linux_x64_llvmaot
                  runtimeVariant: llvmaot
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
          buildConfig: release
          runtimeFlavor: mono
          platforms:
          - linux_x64
          - linux_arm64
          jobParameters:
            testGroup: innerloop
            nameSuffix: AllSubsets_Mono_LLVMFullAOT_RuntimeTests
            buildArgs: -s mono+clr.iltools+clr.hosts+libs+host+packs -c $(_BuildConfig) -lc ${{ variables.debugOnPrReleaseOnRolling }}
                      /p:MonoEnableLLVM=true /p:MonoAOTEnableLLVM=true /p:MonoBundleLLVMOptimizer=true
            postBuildSteps:
              - template: /eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml
                parameters:
                  creator: dotnet-bot
                  testRunNamePrefixSuffix: Mono_Release
                  llvmAotStepContainer: linux_x64_llvmaot
                  runtimeVariant: llvmfullaot
            condition: >-
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_mono_excluding_wasm.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
                eq(variables['isRollingBuild'], true))
